package cn.ym.ymcc.service.impl;

import cn.ym.ymcc.domain.Systemdictionary;
import cn.ym.ymcc.domain.Systemdictionary;
import cn.ym.ymcc.mapper.SystemdictionaryMapper;
import cn.ym.ymcc.mapper.SystemdictionaryMapper;
import cn.ym.ymcc.mapper.SystemdictionaryitemMapper;
import cn.ym.ymcc.query.SystemdictionaryQuery;
import cn.ym.ymcc.result.PageList;
import cn.ym.ymcc.service.ISystemdictionaryService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 210513347@qq.com
 * @since 2023-05-04
 */
@Service
public class SystemdictionaryServiceImpl extends ServiceImpl<SystemdictionaryMapper, Systemdictionary> implements ISystemdictionaryService {
    @Autowired
    private SystemdictionaryMapper systemdictionaryMapper;
    @Autowired
    private SystemdictionaryitemMapper systemdictionaryitemMapper;

    @Override
    public PageList<Systemdictionary> queryPage(SystemdictionaryQuery query) {
        //1.查询总数量 - 前端计算分页栏
        Long count = systemdictionaryMapper.queryCount(query);
        if(count < 1){//没有数据
            return new PageList<>();
        }
        //2.查询当前页的分页数据 - 前端展示当前页的数据
        List<Systemdictionary> list = systemdictionaryMapper.queryData(query);
        return new PageList<>(count,list);
    }

    @Override
    public boolean deleteById(Serializable id) {
        systemdictionaryitemMapper.deleteByParentId(id);
        return super.deleteById(id);
    }
}
